﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace PlusTween
{
    public class PlusTweenScale : PlusTweenBase
    {

        public Vector3 from = Vector3.zero;
        public Vector3 to = Vector3.one;
        
        public Vector3 value
        {
            get {
                return transform.localScale;
            }
            set
            {
                transform.localScale = value;
            }
        }

        public TweenScale tween
        {
            get
            {
                if (null == _tween) { _tween = this.gameObject.GetComponent<TweenScale>(); }
                if (null == _tween) { _tween = this.gameObject.AddComponent<TweenScale>(); _tween.animationCurve = animationCurve; }

                return _tween as TweenScale;
            }
        }

        private void OnEnable()
        {
            if (isBronOrigin) { SetValueFrom(); }
        }

        private void OnDisable()
        {
            tween.enabled = false;
        }

        public override void StartIn()
        {
            tween.duration = duration;
            tween.from = from;
            tween.to = to;

            if (AnimationOrTween.Direction.Forward == tween.direction)
            {
                tween.ResetToBeginning();
                tween.PlayForward();
            }
            else if (AnimationOrTween.Direction.Reverse == tween.direction)
            {
                tween.tweenFactor = 0;
                tween.PlayForward();
            }
        }

        public override void StartOut()
        {
            tween.duration = duration;
            tween.from = from;
            tween.to = to;

            if (AnimationOrTween.Direction.Forward == tween.direction)
            {
                tween.tweenFactor = 1;
                tween.PlayReverse();
            }
            else if (AnimationOrTween.Direction.Reverse == tween.direction)
            {
                tween.ResetToBeginning();
                tween.PlayReverse();
            }
        }

        public override void SetValueFrom() { value = from; }
        public override void SetValueTo() { value = to;  }
    }
}


